package com.easy.service.impl;

import com.easy.bean.Inventory;
import com.easy.mapper.InventoryDao;
import com.easy.service.InventoryService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InventoryServiceImpl implements InventoryService {

    @Autowired
    InventoryDao inventoryDao;

    @Override
    public Inventory add(Inventory inventory) {
        // 设置默认的软删除字段值
        if (inventory.getIs_deleted() == null) {
            inventory.setIs_deleted(0);
        }
        inventoryDao.add(inventory);
        return inventoryDao.one(inventory.getId());
    }

    @Override
    public int del(Integer id) {
        return inventoryDao.del(id);
    }

    @Override
    public Inventory edit(Inventory inventory) {
        inventoryDao.edit(inventory);
        return inventoryDao.one(inventory.getId());
    }

    @Override
    public List<Inventory> all(String itemType, String location) {
        return inventoryDao.all(itemType, location);
    }

    @Override
    public Inventory one(Integer id) {
        return inventoryDao.one(id);
    }

    @Override
    public void page(Page page, Inventory inventory) {
        int count = inventoryDao.pageCount(inventory);
        Object data = inventoryDao.page(page, inventory);
        page.setCount(count);
        page.setData(data);
    }
}